import api from "../../api/api";
import cateDataList from "../../data/cate";
import { category } from "../../api/conf";
import { searCate } from "../../api/conf";
import { search } from "../../api/conf";
import { userList } from "../../api/conf";
import { userDelete } from "../../api/conf";
Page({
  data: {
    curIndex: 0,
    list: [],
    cateId: null,
    dataList: [],
    page: 1,
    reTurn: false,
    searchPage: false,
    searchContent: [],
    searpage: 1,
    Qvaule: null,
    frist: false,
    searclosebtn: false,
    num: 0,
    orderBy: 0,
    cateName: "",
    subCate: [],
  },
  onLoad: function (options) {
    this.setData({
      list: cateDataList,
      frist: true,
      cateId: "sysAuthUser",
    });
  },
  onReady: function () {},

  switchRightTab: function (e) {
    let index = parseInt(e.target.dataset.index);
    let cateId = e.target.dataset.cateid;
    let cateName = e.target.dataset.name;
    console.log("cateid,cateName", index, cateId, cateName);
    this.setData({
      curIndex: index,
      cateId: cateId,
      produList: [],
      subCate: [],
      page: 1,
      reTurn: false,
      num: 0,
      orderBy: 0,
      cateName: cateName,
    });
  },
  search: function (e) {
    var that = this;
    this.setData({
      Qvaule: e.detail.value,
      searpage: 1,
      searclosebtn: true,
    });
    wx.showNavigationBarLoading();
    api
      .get(search, {
        q: that.data.Qvaule,
        page: that.data.searpage,
      })
      .then((res) => {
        that.setData({
          searchContent: res.Data.Items,
          searchPage: true,
        });
        wx.hideNavigationBarLoading();
      });
  },

  lower: function (e) {
    this.setData({
      page: this.data.page + 1,
    });
    this.getProduct();
  },

  //搜索页面滚动加载
  searchLower: function () {
    var that = this;
    this.setData({
      searpage: this.data.searpage + 1,
    });
    wx.showNavigationBarLoading();
    api
      .get(search, {
        q: that.data.Qvaule,
        page: that.data.searpage,
      })
      .then((res) => {
        that.setData({
          searchContent: that.data.searchContent.concat(res.Data.Items),
        });
        wx.hideNavigationBarLoading();
      });
  },
  menuClick: function (e) {
    let mum = e.currentTarget.dataset.num;
    let by = this.data.orderBy;
    if (mum == 1 && by != 21) {
      by = 21;
    } else if (mum == 1 && by == 21) {
      by = 20;
    } else if (mum == 3 && by != 6) {
      by = 6;
    } else if (mum == 3 && by == 6) {
      by = 5;
    } else if (mum == 2 && by != 25) {
      by = 25;
    } else if (mum == 2 && by == 25) {
      by = 26;
    } else {
      by = 0;
    }
    this.setData({
      produList: [],
      num: mum,
      orderBy: by,
      page: 1,
      reTurn: false,
    });
    this.getProduct();
  },

 
});
